<template>
  <div class="app-container">
    <div class="content-step">
        <div class="step">
          <el-steps :active="active" finish-status="success">
            <el-step title="输入域名"></el-step>
            <el-step title="域名解析"></el-step>
            <el-step title="完成"></el-step>
        </el-steps>
        </div>
    </div>
    <el-form :model="domainNameData" :rules="rules" ref="domainNameForm">
    <div class="container">
      <div class="container-title">绑定已有域名</div>
      <div class="title">将你已有的店铺域名绑定到你的店铺中，方便熟悉你店铺
        <br>域名的顾客更容易找到你的店铺并进行购物</div>
          <el-form-item prop="domainName">
              <el-input class="container-input"  v-model="domainNameData.domainName" placeholder="例如：www.shopplus.vip" />
          </el-form-item>

        <div class="title">输入你想要连接的域名</div>
    </div>
    <div class="btn">
      <el-button  @click="handleReturn">取消</el-button>
      <el-button type="primary" @click="handleNext('domainNameForm')" :loading="submitLoading">下一步</el-button>
    </div>
     </el-form>
  </div>
</template>

<script>
import { bindDomainName } from '@/api/domain';
export default {
    name: 'domain-name-add',
    data () {
        return {
            domainNameData: {
                domainName: ''
            },
            submitLoading: false,
            active: 0,
            params: {},
            config: {},
            settingVisible: false,
            rules: {
                domainName: [
                    { required: true, pattern: /^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$/, message: '请输入正确的域名地址' }
                ]
            }
        };
    },
    methods: {
        handleNext (formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.domainNameData.siteId = this.siteId;
                    this.submitLoading = true;
                    bindDomainName(this.domainNameData).then(res => {
                        if (res.data.binded) { // 绑定成功跳第三步
                            this.$router.push({name: 'domain-name-complete', query: {DNSBind: res.data}});
                        } else { // 不成功跳第二步
                            this.$router.push({name: 'domain-name-next', query: {DNSBind: res.data}});
                        }
                        this.submitLoading = false;
                    });
                }
            });

            // this.$router.push({name: 'domain-name-next'});
        },
        handleReturn () {
            this.$router.push({name: 'domain-name'});
        }
    },
    computed: {
        siteId () {
            return this.$store.state.user.siteId;
        }
    }
};
</script>

<style lang="scss" scoped>
.btn{
   margin: 30px;
  padding: 30px;
  display: flex;
  align-content: center;
  justify-content: center;
  // justify-content:flex-end;
}
.content-step{
  display: -webkit-box;
 -webkit-box-pack: center;
  justify-content: center;
  margin: 20px 30px 20px 30px;
}
.step{
  height: 100%;
  width: 60%;
}
.container {
  height: 300px;
  margin: 20px 30px 10px 30px;
  display: flex;
  flex-direction: column;
  line-height: 30px;
justify-content: center;
  align-items: center;
  background-color: #ffffff;
}
.container-title{
  font-size: 18px;
  font-weight: 500;
  color:#30344f
}
.title{
  font-size: 16px;
  color:#7e849c;
}
.container-input{
  margin: 20px 0 20px 0;
  height: 30px;
  width: 450px;
}
.content{
    margin: 15px 0 0 30px;
}
</style>
